# Maintainer: David Runge <dvzrv@archlinux.org>

_name=fire
pkgname=python-fire
pkgver=0.5.0
pkgrel=2
pkgdesc="A library for automatically generating command line interfaces"
arch=(any)
url="https://github.com/google/python-fire"
license=(Apache)
depends=(
  python
  python-six
  python-termcolor
)
makedepends=(
  python-build
  python-installer
  python-setuptools
  python-wheel
)
checkdepends=(
  python-hypothesis
  python-levenshtein
  python-mock
  python-pytest
)
source=(
  https://files.pythonhosted.org/packages/source/${_name::1}/$_name/$_name-$pkgver.tar.gz
  $pkgname-0.5.0-python3.11.patch
)
sha256sums=('a6b0d49e98c8963910021f92bba66f65ab440da2982b78eb1bbf95a0a34aacc6'
            '5067d7dadb4ebc8e47dfc8080c3551d7efe9411e49c49275cdbdedf8d872fedd')
b2sums=('eecaceb95faba05a0f2b157560f690d9cee0a10939c2f376b8563955171299ada4b522775450443d9ff9ad31092cf4967a7fc77f7cd1eaab30c9450291a9dbeb'
        '4a75b46429cfad6b7c55e2fb36df10875f3950858c55112c120d269f7c72d717b3c12d99d61ed15d3ec345195503cc34f42e4481e121314cac364eee72509489')

prepare() {
  # fix for python >= 3.11: https://github.com/google/python-fire/issues/427
  patch -Np1 -d $_name-$pkgver -i ../$pkgname-0.5.0-python3.11.patch
}

build() {
  cd $_name-$pkgver
  python -m build --wheel --no-isolation
}

check() {
  cd $_name-$pkgver
  export PYTHONPATH="build:$PYTHONPATH"
  pytest -v
}

package() {
  local _site_packages=$(python -c "import site; print(site.getsitepackages()[0])")

  cd $_name-$pkgver
  python -m installer --destdir="$pkgdir" dist/*.whl
  install -vDm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname/"
  # remove test files: https://github.com/google/python-fire/issues/422
  rm -frv "$pkgdir/$_site_packages/$_name/"{testutils,*_test}.py
}
